package com.zhz.workqueue;

import com.google.gson.Gson;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zhz.utils.RabbitConstant;
import com.zhz.utils.RabbitUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 
 * @date ：Created in 2021/01/31
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description: 发送方（服务端/生产者）
 **/
public class OrderSystem {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(RabbitConstant.QUEUE_SMS,false,false,false,null);
        for (int i = 1; i <= 100; i++) {
            Sms sms=new Sms("乘客"+i,"10086"+i,"您的车票已经预定");
            String json = new Gson().toJson(sms);
            channel.basicPublish("",RabbitConstant.QUEUE_SMS,null,json.getBytes());
        }
        System.out.println("发送数据成功");
        channel.close();
        connection.close();
    }
}
